let logistEle = document.querySelector('.top-t')    //导航
let loginEle = document.querySelector('.login')    //登录
let registEle = document.querySelector('.regist')    //注册
let backEle = document.querySelector('.back')    //退出
let personEle = document.querySelector('.person')    //   用户


function loginRegist() {
    logistEle.addEventListener('click', function (e) {
        e = e || window.event
        let target = e.target || e.srcElement
        if (target.getAttribute('class') == 'login') {
            location.href = './login.html'
        }
        if (target.getAttribute('class') == 'regist') {
            location.href = './regist.html'
        }
    })
}
loginRegist()
/********---------------------------显示账户名----------------------------------***/
function onContent() {
    let personArrayStr = localStorage.getItem('TRUEDATA') //从locaStorage获取数据
    let personList = JSON.parse(personArrayStr) || [] //转对象 默认为空
    if (personList != '') {
        loginEle.innerHTML = `${personList[0]}`
        registEle.innerHTML = '购物车'
        personEle.style.display = 'inline-block'
        backEle.style.display = 'block'
    }

    function onBack() {
        backEle.addEventListener('click', function () {
            localStorage.removeItem('TRUEDATA',)
            loginEle.innerHTML = '🙂你好！请登录'
            registEle.innerHTML = '免费注册'
            personEle.style.display = 'none'
            backEle.style.display = 'none'
            location.href = 'login.html'
        })
    }
    onBack()
}
onContent()